package 
{
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;
	import objects.LoaderComponent;

	import helpers.LoaderManager;

	import helpers.Screen;

	
	/**
	 * ...
	 * @author drowller
	 */
	public class Main extends Sprite 
	{
		private var _screen:Screen;
		private var loader:LoaderManager;
		private var loaderComp:LoaderComponent;
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point

			//stage.stage3Ds[0].addEventListener(Event.CONTEXT3D_CREATE, onContextCreate);
			//stage.stage3Ds[0].requestContext3D();
			loader = new LoaderManager();
			
		
			setStage();
			addScreen();
		addChild(loader.containerSWF);
			//var ldr:URLLoader = new URLLoader();
			//ldr.dataFormat = URLLoaderDataFormat.BINARY;
			//ldr.addEventListener(Event.COMPLETE, onComp);
			//ldr.load(new URLRequest("CandyMaster.swf"));
			//addChild(ldr);

		}
		
		
		private function onContextCreate(e:Event):void 
		{
			
			trace("Stage3D");
			
		}
		
		private function onComp(e:Event):void 
		{
			//trace("!!!!!")
			//var info:LoaderInfo = e.currentTarget as LoaderInfo;
			//addChild(info.content as MovieClip)
			//var ba:ByteArray = e.target.data;
			
			//var load:Loader = new Loader();
			//load.loadBytes(ba);
			//addChild(load);
		}
		
		private function setStage():void 
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
		}
		
		private function addScreen():void 
		{
			_screen = new Screen(stage,loader.next,loader.prev);
			addChild(_screen);
		}
		
	}
	
}